/**
* Local context function testing
*
* author: Maciej Rubikowski
*/

#include "KOV.h"
#include <iostream>

int main(int argc, char *argv[]) {
	_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
	_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
	{

		FormalContext *FC = new FormalContext;

		OAPair oa1;
		OAPair oa2;
		OAPair oa3;
		OAPair oa4;
		OAPair oa5;
		OAPair oa6;
		OAPair oa7;
		OAPair oa;

		/*
		oa.first = new ObjectSet;
		oa.first->data.insert(2);
		oa.first->data.insert(3);
		oa.first->data.insert(6);

		oa.second = new AttributeSet;
		oa.second->data.insert(Attribute(4));

		oa1.first = new ObjectSet;
		oa1.first->data.insert(Object(2));
		oa1.first->data.insert(Object(4));
		oa1.first->data.insert(Object(5));
		oa1.first->data.insert(Object(6));

		oa1.second = new AttributeSet;
		oa1.second->data.insert(Attribute(1));
		oa1.second->data.insert(Attribute(6));

		oa2.first = new ObjectSet;
		oa2.first->data.insert(Object(1));
		oa2.first->data.insert(Object(2));
		oa2.first->data.insert(Object(4));
		oa2.first->data.insert(Object(6));

		oa2.second = new AttributeSet;
		oa2.second->data.insert(Attribute(3));

		oa3.first = new ObjectSet;
		oa3.first->data.insert(Object(1));
		oa3.first->data.insert(Object(3));
		oa3.first->data.insert(Object(4));
		oa3.first->data.insert(Object(5));

		oa3.second = new AttributeSet;
		oa3.second->data.insert(Attribute(5));

		oa4.first = new ObjectSet;
		oa4.first->data.insert(Object(2));
		oa4.first->data.insert(Object(3));
		oa4.first->data.insert(Object(4));
		oa4.first->data.insert(Object(6));

		oa4.second = new AttributeSet;
		oa4.second->data.insert(Attribute(8));


		FC->data.push_back(oa1);
		FC->data.push_back(oa2);
		FC->data.push_back(oa3);
		FC->data.push_back(oa4);

		//commence local context w/o minSup and deltaClosure test
		FormalContext *FC2 = LocalContext(oa, FC);//new FormalContext();
		*/

		oa.first = new ObjectSet;
		oa.first->data.insert(1);
		oa.first->data.insert(4);
		oa.first->data.insert(5);

		oa.second = new AttributeSet;
		oa.second->data.insert(Attribute(2));

		oa1.first = new ObjectSet;
		oa1.first->data.insert(Object(4));

		oa1.second = new AttributeSet;
		oa1.second->data.insert(Attribute(7));

		oa2.first = new ObjectSet;
		oa2.first->data.insert(Object(1));
		oa2.first->data.insert(Object(4));
		oa2.first->data.insert(Object(5));

		oa2.second = new AttributeSet;
		oa2.second->data.insert(Attribute(2));

		oa3.first = new ObjectSet;
		oa3.first->data.insert(Object(2));
		oa3.first->data.insert(Object(3));
		oa3.first->data.insert(Object(6));

		oa3.second = new AttributeSet;
		oa3.second->data.insert(Attribute(4));

		oa4.first = new ObjectSet;
		oa4.first->data.insert(Object(2));
		oa4.first->data.insert(Object(4));
		oa4.first->data.insert(Object(5));
		oa4.first->data.insert(Object(6));

		oa4.second = new AttributeSet;
		oa4.second->data.insert(Attribute(1));
		oa4.second->data.insert(Attribute(6));

		oa5.first = new ObjectSet;
		oa5.first->data.insert(Object(1));
		oa5.first->data.insert(Object(2));
		oa5.first->data.insert(Object(4));
		oa5.first->data.insert(Object(6));

		oa5.second = new AttributeSet;
		oa5.second->data.insert(Attribute(3));

		oa6.first = new ObjectSet;
		oa6.first->data.insert(Object(1));
		oa6.first->data.insert(Object(3));
		oa6.first->data.insert(Object(4));
		oa6.first->data.insert(Object(5));

		oa6.second = new AttributeSet;
		oa6.second->data.insert(Attribute(5));

		oa7.first = new ObjectSet;
		oa7.first->data.insert(Object(2));
		oa7.first->data.insert(Object(3));
		oa7.first->data.insert(Object(4));
		oa7.first->data.insert(Object(6));

		oa7.second = new AttributeSet;
		oa7.second->data.insert(Attribute(8));

		FC->data.push_back(oa1);
		FC->data.push_back(oa2);
		FC->data.push_back(oa3);
		FC->data.push_back(oa4);
		FC->data.push_back(oa5);
		FC->data.push_back(oa6);
		FC->data.push_back(oa7);


		AttributeSet as1;
		AttributeSet as2;
		as1.data.insert(2);
		as2.data.insert(5);
		DeltaClosure dc;
		dc.push_back(as1);
		dc.push_back(as2);
		unsigned int minSup = 2;

		FormalContext *FC2 = LocalContextMinSup(oa, dc, FC, minSup);




		for (int i = 0; i < FC2->data.size(); ++i) {
			for(std::set<Object>::iterator j = FC2->data[i].first->data.begin(); j != FC2->data[i].first->data.end(); ++j)
				std::cout << *j;
			std::cout << " : ";
			for(std::set<Attribute>::iterator j = FC2->data[i].second->data.begin(); j != FC2->data[i].second->data.end(); ++j)
				std::cout << *j;
			std::cout << std::endl;
		}


		for (std::vector<OAPair>::iterator it = FC2->data.begin(); it != FC2->data.end(); ++it) {
			delete it->first;
			delete it->second;
		}
		delete FC2;
		for (std::vector<OAPair>::iterator it = FC->data.begin(); it != FC->data.end(); ++it) {
			delete it->first;
			delete it->second;
		}
		delete FC;
		delete oa.first;
		delete oa.second;
	}
	_CrtDumpMemoryLeaks();
	system("PAUSE");
	return 0;
}